<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Postar Ideia</title>
        <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/reset.css"/>
        <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/style.css"/>
        <script type="text/javascript" src="<?php echo base_url() ?>js/jquery-1.6.js"></script>
        <script type="text/javascript" src="<?php echo base_url() ?>js/jquery.validate.js" ></script>
        <script type="text/javascript" src="<?php echo base_url(); ?>js/core.js"></script>
        <script type="text/javascript" src="<?php echo base_url(); ?>js/validate_form.js"></script>
    </head>
    <body>
        <?php
        include ("includes/nav_bar.php");
        ?>
        <div id="main-content">
            <div id="conteudo" style="width: 65%;">
                <form action="<?php echo base_url() ?>ideias/salvarPostagem" method="post" id="form_ideia" class="form_ideia">
                    <h1>Compartilhe Sua Idéia</h1>
                    <?php if(isset($view_msg))
                        echo $view_msg; ?>
                    <p><label class="medio">Titulo:</label><input type="text" name="titulo" value="<?php if(isset($view_titulo))
                        echo $view_titulo; ?>" class="grande" id="titulo"/></p>
                    <p><label class="medio">Categoria:</label><select name="categoria">
                            <option value="" selected></option>
                            <?php
                            foreach($view_categorias as $categoria):
                                if($categoria->fk_int_idPai == 0) {
                                    echo "<option style=\"font-weight: bold;\" value=\"$categoria->pk_int_id\">".$categoria->char_nome."</option>";
                                    mostrarSubCategorias($view_categorias, $categoria->pk_int_id, 0);
                                }
                            //echo "<option value=$categoria->pk_int_id;></option>";
                            endforeach;
                            ?>
                        </select></p>
                    <p><label class="medio" style="vertical-align: top;">Descrição:</label><textarea name="ideia" cols="54" rows="10" id="ideia"><?php if(isset($view_descricao))
                                echo $view_descricao; ?></textarea></p>
                    <p><input type="submit" name="enviar" value="Enviar" class="btn"/></p>
                </form>
            </div>
        </div>
    </body>
</html>

<?php

function mostrarSubCategorias($categorias, $id_categoria, $indentacao) {
    $indentacao++;
    foreach($categorias as $subcategoria) {
        if($subcategoria->fk_int_idPai != 0 && $subcategoria->fk_int_idPai == $id_categoria) {
            $indent = "";
            for($i = 0; $i < $indentacao; $i++)
                $indent .= "»";
            echo "<option value=\"$subcategoria->pk_int_id\">$indent ".$subcategoria->char_nome."</option>";
            mostrarSubCategorias($categorias, $subcategoria->pk_int_id, $indentacao);
        }
    }
}
?>